﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows.Controls;

namespace TournamentDatabase.Rules
{
	class NumberValidationRule : ValidationRule
	{
		int m_maxNumber = int.MaxValue;
		int m_minNumber = int.MinValue;

		public int MinNumber
		{
			get { return m_minNumber; }
			set { m_minNumber = value; }
		}

		public int MaxNumber
		{
			get { return m_maxNumber; }
			set { m_maxNumber = value; }
		}


		public override ValidationResult Validate(object value, CultureInfo cultureInfo)
		{
			// Is it a number?
			int number = 0;
			if (!int.TryParse((string)value, out number))
				return new ValidationResult(false, "Value is not of type Gender.");

			// Is it an allowable number?
			if (number > m_maxNumber)
				return new ValidationResult(false, "Number must be less than " + m_maxNumber + ".");
			if (number < m_minNumber)
				return new ValidationResult(false, "Number must be greater than " + m_minNumber + ".");

			// Gender is valid
			return new ValidationResult(true, null);
		}
	}
}
